<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <ul onclick="handleClickUl()">
        <li>nowcoder</li>
        <li>nowcoder</li>
        <li>nowcoder</li>
    </ul>
</body>
<script>
    function handleClickUl() {
        alert("ul被点击了！");
    }

    let lis = Array.from(document.querySelectorAll("li"));
    lis.forEach(v => {
        v.onclick = function(e) {
            alert("li被点击了！");
            // 阻止事件冒泡
            e.stopPropagation();
        }
    })

</script>
</html>